import UaParser from 'ua-parser-js';

/**
 * 添加 收集用户浏览器信息
 *  {
 *      ua:
 *          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
 *      browser: { name: 'Chrome', version: '77.0.3865.90', major: '77' },
 *      engine: { name: 'Blink', version: 'undefined' },
 *      os: { name: 'Windows', version: '10' },
 *      device: {
 *          vendor: 'undefined',
 *          model: 'undefined',
 *          type: 'undefined'
 *      },
 *      cpu: { architecture: 'amd64' }
 *  }
 */

const getUaData = _ => {
  return new UaParser().getResult();
};

export default {
  namespaced: true,
  state: {
    // 用户 UA

    ...getUaData(),
  },
  mutations: {
    /**
     * @description 记录 UA
     * @param {Object} state state
     */
    get(state) {
      state = getUaData();
    },
  },
};
